import { fileURLToPath, URL } from 'node:url'
// import compressPlugin from 'vite-plugin-compression'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import px2rem from 'postcss-plugin-px2rem'
// https://vitejs.dev/config/
export default defineConfig({
    configureWebpack: (config) => {
        config.devtool = false
    },
    productionSourceMap: false,
    plugins: [
        vue(),
        // compressPlugin({
        //     //gzip静态资源压缩
        //     verbose: true, // 默认即可
        //     disable: false, //开启压缩(不禁用)，默认即可
        //     deleteOriginFile: true, //删除源文件
        //     threshold: 10240, //压缩前最小文件大小
        //     algorithm: 'gzip', //压缩算法
        //     ext: '.gz', //文件类型
        // }),
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url)),
            '~': fileURLToPath(new URL('./public', import.meta.url)),
        },
    },
    // 以下部分是配置公用scss的代码
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: `@use '@/assets/css/variable.scss' as *;`,
            },
        },
        postcss: {
            plugins: [
                px2rem({
                    rootValue: 192,
                    exclude: /(svg)/,
                    // mediaQuery: false,
                    minPixelValue: 3,
                }),
            ],
        },

        // loaderOptions: {
        //     sass: {
        //         prependData: '@use "@/assets/css/element.scss" as *;',
        //     },
        // },
    },

    server: {
        host: '0.0.0.0',
        port: 9001,
        // host: '192.168.0.200',
        // port: 5001,
        proxy: {
            '/papi': {
                target: 'http://49.234.30.189:9007', //实际请求地址
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/papi/, ''),
            },
        },
    },

    base: './',
})
